package leetcode.datastructure.array;

public class Program135HandOutCandy {

    public Program135HandOutCandy() {

    }

    public int candy(int[] ratings) {
        return office(ratings);
    }

    public int office(int[] ratings) {
        int n = ratings.length;
        int ret = 1;
        // 模拟左侧有点，默认下标0是比虚拟点大
        int inc = 1, dec = 0, pre = 1;
        for (int i = 1; i < n; i++) {
            if (ratings[i] >= ratings[i - 1]) {
                dec = 0;
                // 存在相等的时候，默认调整到最低
                pre = ratings[i] == ratings[i - 1] ? 1 : pre + 1;
                ret += pre;
                inc = pre;
            } else {
                // 记录数量，可以理解补充升高的数量
                dec++;

                // 波峰变动增加
                if (dec == inc) {
                    dec++;
                }
                ret += dec;
                pre = 1;
            }
        }
        return ret;
    }

    public int person(int[] arr) {
        return -1;
    }


    public static void main(String[] args) {

    }
}
